/******************************************************************************
*
*    File Name:  programs.V
*      Version:  1.0
*         Date:  June 13th, 2013
*        Model:  
*    Simulator:  Questa Sim- Mentor Graphics (Version 64 10.2a)
*
* Dependencies:  DDRTestbench.sv
*
*       Author:  Nachiket Khasbag & Nikhil Patil 
*        Email:  nachiket@pdx.edu, pnikhil@gmail.com
*        Phone:  404-660-0757, 971-300-1728
*   University:  Portland State University
*
*
******************************************************************************/


`timescale 1ns / 1ps

program testcase(input clk);
  
integer Case,i,ts;

initial
begin
  test.v=new();
  $display("\n\n*************************  DDR3 DRAM INTERFACE VERIFICATION  *************************\n\n");

 for(i=1; i<25; i++)
   begin
   Case = i;
   ts   = 0;
	
//
//PRECHARGE TEST CASES
//

//CHECK PRECHARGE BANK 0 COMMAND
if (Case == 1)
begin 
	
		$display ("TEST SCENARIO :1 CHECK PRECHARGE BANK COMMAND\n");
		ts++;
		#(1*test.full_clk); test.nop (2);                 // NOP
		#(9*test.full_clk); test.precharge(0);            // PRECHARGE BANK
		#(1*test.full_clk); test.nop (2);                 // NOP
		#(1*test.full_clk); test.nop (2);                 // NOP
		  
		$display("\n**************************************************************************************\n");
end


// CHECK ACTIVATE BANK COMMAND
if(Case == 2)
  
	begin 
		ts++;
		for(int b=0; b<1;b++)
		begin
		  $display ("TEST SCENARIO :2 CHECK ACTIVATE BANK COMMAND\n");
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(b);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(8*test.full_clk); test.activate (b,10);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		end	
		$display("\n**************************************************************************************\n");	
  end 
  
// CHECK READ
if(Case == 3)
  
	begin 
		ts++;
		for(int b=0; b<1;b++)
		begin
		  $display ("TEST SCENARIO :3 CHECK READ COMMAND\n");
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(b);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (b,10);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.read(10);                    // READ
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(b);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  		 
		end	
		$display("\n**************************************************************************************\n");	
  end  
  
// CHECK WRITE
if(Case == 4)
  
	begin 
		ts++;
		for(int b=0; b<1;b++)
		begin
		  $display ("TEST SCENARIO :4 CHECK WRITE COMMAND\n");
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(b);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (b,10);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.write(10);                   // WRITE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(b);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  		 
		end	
		$display("\n**************************************************************************************\n");	
  end  

// CHECK CONSECUTIVE READ
if(Case == 5)
  
	begin 
		ts++;
		$display ("TEST SCENARIO :5 CHECK CONSECUTIVE READ COMMAND\n");
		for(int b=0; b<2;b++)
		begin
		  
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (0,10);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.read(20);                    // READ
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		   	 
		end	
		$display("\n**************************************************************************************\n");	
  end  

// CHECK CONSECUTIVE WRITE
if(Case == 6)
  
	begin 
		ts++;
    $display ("TEST SCENARIO :6 CHECK CONSECUTIVE WRITE COMMAND\n");
		for(int b=0; b<2;b++)
		begin

		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (0,10);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.write(20);                   // WRITE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  		 
		end	
		$display("\n**************************************************************************************\n");	
  end 
  
// 
if(Case == 7)
  
	begin 
		ts++;
    $display ("TEST SCENARIO :7 CHECK WRITE AFTER READ COMMAND\n");
		  
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (0,10);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.read(20);                    // READ
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  
		  $display("\n");

		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (0,10);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.write(20);                   // WRITE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  
		$display("\n**************************************************************************************\n");	
  end 
   
// CHECK READ AFTER WRITE
if(Case == 8)
  
	begin 
		ts++;
    $display ("TEST SCENARIO :8 CHECK READ AFTER WRITE\n");
		  
		  //#(1*test.full_clk); test.nop (2);                     // NOP
		  //#(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (1,20);             // ACTIVATE
		  #(6*test.full_clk); test.write(20);                   // WRITE
		  #(2*test.full_clk); test.precharge(1);                // PRECHARGE BANK
//		  #(1*test.full_clk); test.nop (2);                     // NOP
		  
		  $display("\n");

//		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(2*test.full_clk); test.precharge(1);                // PRECHARGE BANK
//		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(2*test.full_clk); test.activate (1,20);             // ACTIVATE
//		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(2*test.full_clk); test.read(20);                    // READ
		  //#(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.precharge(1);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  
		$display("\n**************************************************************************************\n");	
  end 


// CHECK ALTERNATE READ & WRITE
if(Case == 9)
  
	begin 
		ts++;
    $display ("TEST SCENARIO :9 CHECK ALTERNATE READ & WRITE\n");
		  
		  $display("\n FIRST WRITE\n");
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (0,10);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.write(20);                   // WRITE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  
		  $display("\n READ\n");

		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (0,10);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.read(20);                    // READ
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  
		  $display("\n WRITE\n");
		  
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (0,10);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.write(20);                   // WRITE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  
		 		  
		$display("\n**************************************************************************************\n");	
  end 


// CHECK RANDOM READ
if(Case == 10)
     
	begin 
		ts++;
		test.v=new();
		$display ("TEST SCENARIO :10 CHECK RANDOM READCOMMAND\n");
		for(int d=1; d<11;d++)
		begin
		  test.v.randomize();
		  $display ("\nRANDOM READ:%0d \n",d);
		 
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(test.v.bank);      // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (test.v.bank,test.v.row);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.read(test.v.col);                    // READ
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(test.v.bank);      // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  		 
		end	
		$display("\n**************************************************************************************\n");	
  end  
  

// CHECK RANDOM WRITE
if(Case == 11)
      
	begin 
		ts++;
		test.v=new();
		$display ("TEST SCENARIO :11 CHECK RANDOM WRITE COMMAND\n");
		for(int b=1; b<11;b++)
		begin
		  test.v.randomize();
		  $display ("\nRANDOM WRITE:%0d \n",b);
		 
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(test.v.bank);      // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (test.v.bank,test.v.row); // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.write(test.v.col);           // WRITE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(test.v.bank);      // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  		 
		end	
		$display("\n**************************************************************************************\n");	
  end  


// CHECK ROLL BACK ROW AND COLUMN ADDRESS
if(Case == 12)
  
	begin 
		ts++;
		$display ("TEST SCENARIO :12 CHECK ROLL BACK ROW AND COLUMN ADDRESS\n");
		  
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.activate (0,130);            // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(6*test.full_clk); test.read(135);                   // READ
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(9*test.full_clk); test.precharge(0);                // PRECHARGE BANK
		  #(1*test.full_clk); test.nop (2);                     // NOP

		$display("\n**************************************************************************************\n");	
		$display("\n******************************TIMING CONSTRAINT CHECKING******************************\n");
  end  
    

// TIMING CONSTRAINT CHECKING

// ACTIVATE TO ACTIVATE tRRD VIOLATION
if(Case == 13)
  
	begin 
		ts++;
		$display ("TEST SCENARIO :13 CHECK ACTIVATE TO ACTIVATE tRRD VOILATION\n");

		  #(1*test.full_clk); test.precharge (0);               // PRECHARGE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(1*test.full_clk); test.activate (0,25);            // ACTIVATE
		  #(1*test.full_clk); test.activate (0,30);            // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
	
		$display("\n**************************************************************************************\n");	
  end  

// ACTIVATE TO READ/WRITE tRCD VIOLATION
if(Case == 14)
  
	begin 
		ts++;
		$display ("TEST SCENARIO :14 CHECK ACTIVATE TO READ/WRITE tRCD VIOLATION\n");

		  #(1*test.full_clk); test.precharge (0);               // PRECHARGE
		  #(8*test.full_clk); test.nop (2);                     // NOP
		  #(1*test.full_clk); test.activate (0,15);             // ACTIVATE
		  #(1*test.full_clk); test.read (25);                   // READ
		  #(1*test.full_clk); test.nop (2);                     // NOP
		   	 
		$display("\n**************************************************************************************\n");	
  end  

// ACTIVATE TO PRECHARGE tRAS VIOLATION
if(Case == 15)
  
	begin 
		ts++;
		$display ("TEST SCENARIO :15 CHECK ACTIVATE TO PRECHARGE tRAS VIOLATION\n");

		  #(1*test.full_clk); test.precharge (0);               // PRECHARGE
		  #(8*test.full_clk); test.nop (2);                     // NOP
		  #(1*test.full_clk); test.activate (0,15);             // ACTIVATE
		  #(1*test.full_clk); test.precharge (0);               // PRECHARGE
		  #(1*test.full_clk); test.nop (2);                     // NOP

		$display("\n**************************************************************************************\n");	
  end  

// PRECHARGE TO ACTIVATE tRP VIOLATION
if(Case == 16)
  
	begin 
		ts++;
		$display ("TEST SCENARIO :16 CHECK PRECHARGE TO ACTIVATE tRP VIOLATION\n");
		  
		  #(1*test.full_clk); test.precharge (0);               // PRECHARGE
		  #(1*test.full_clk); test.activate (0,15);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP

		$display("\n**************************************************************************************\n");	
  end  

// READ/WRITE AFTER PRECHARGE WITHOUT ACTIVATE : BANK NOT OPEN ERROR
if(Case == 17)
  
	begin 
		ts++;
		$display ("TEST SCENARIO :17 READ/WRITE AFTER PRECHARGE WITHOUT ACTIVATE : BANK NOT OPEN ERROR\n");
		  
		  #(1*test.full_clk); test.precharge (0);               // PRECHARGE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(1*test.full_clk); test.read (10);                   // READ
		  #(1*test.full_clk); test.nop (2);                     // NOP

		$display("\n**************************************************************************************\n");	
  end  

// AUTO REFRESH TO AUTO REFRESH tRC VIOLATION
if(Case == 19)
  
	begin 
		ts++;
		$display ("TEST SCENARIO :19 AUTO REFRESH TO AUTO REFRESH tRC VIOLATION\n");
		  
		  #(1*test.full_clk); DDR3.refresh;                     // PREFRESH
		  DDR3.refresh;                                         // PREFRESH
		  #(1*test.full_clk); test.nop (2);                     // NOP

		$display("\n**************************************************************************************\n");	
  end  

// READ/WRITE TO PRECHARGE tWR VIOLATION
if(Case == 20)
  
	begin 
		ts++;
		$display ("TEST SCENARIO :20 READ/WRITE TO PRECHARGE tWR VIOLATION\n");
		  
		  #(1*test.full_clk); test.precharge (0);               // PRECHARGE
		  #(8*test.full_clk); test.nop (2);                     // NOP
		  #(1*test.full_clk); test.activate (0,15);             // ACTIVATE
		  #(1*test.full_clk); test.nop (2);                     // NOP
		  #(8*test.full_clk); test.write (25);                   // READ
		  #(1*test.full_clk); test.precharge (0);               // PRECHARGE
		  #(1*test.full_clk); test.nop (2);                     // NOP

		$display("\n**************************************************************************************\n");	
  end  

end
$stop;
end
endprogram